import 'package:flutter/material.dart';
import 'package:goumao_app/Customs/gm_app_util.dart';
import 'package:webview_flutter/webview_flutter.dart';

class GMShowWebPagge extends StatefulWidget {
  final String url;
  final String title;

  const GMShowWebPagge({super.key, required this.url, required this.title});

  @override
  // ignore: library_private_types_in_public_api
  _MyWebViewState createState() => _MyWebViewState();
}

class _MyWebViewState extends State<GMShowWebPagge> {
  late final WebViewController controller;

  @override
  void initState() {
    super.initState();

    // #docregion webview_controller
    controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse(widget.url));
  }

  // #docregion webview_widget
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: GMAppUtil.navText(widget.title),
        elevation: 0,
      ),
      body: WebViewWidget(controller: controller),
    );
  }
}
